package com.ds.web.interceptor;

import com.ds.context.JDSActionContext;
import com.ds.esd.bean.MethodConfig;
import com.ds.esd.engine.ESDFacrory;
import com.ds.esd.engine.EUModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

@Component
public class ModuleInterceptor extends BaseInterceptor {
    private static final Logger logger = LoggerFactory.getLogger(ModuleInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        try {
            String projectName = this.getProjectName(request);
            String euClassName = getCustomClassName(request);
            EUModule euModule = ESDFacrory.getAdminESDClient().getModule(euClassName, projectName);
            if (euModule == null) {
                euModule = ESDFacrory.getAdminESDClient().getCustomModule(euClassName, projectName, new HashMap<>());
            }
            StringBuffer json = ESDFacrory.getAdminESDClient().genJSON(euModule, null, true);
            sendJSON(response, json.toString());
            return false;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }


}